package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.OrderDetail;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.impl.UserOrderServiceImpl;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags = "C端-订单接口")
@RestController("UserOrderController")
@RequestMapping("/user/order/")
public class OrderController {

    @Autowired
    private UserOrderServiceImpl userOrderService;

    @ApiOperation("用户下单")
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        return Result.success(userOrderService.submit(ordersSubmitDTO));
    }

    @ApiOperation("订单支付")
    @PutMapping("/payment")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) {
        return Result.success(userOrderService.payment(ordersPaymentDTO));
    }

    @ApiOperation("查询订单详情")
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> orderDetail(@PathVariable Long id) {
        return Result.success(userOrderService.orderDetail(id));
    }

    @ApiOperation("历史订单查询")
    @GetMapping("/historyOrders")
    public Result<PageResult> historyOrders(OrdersPageQueryDTO ordersPageQueryDTO) {
        return Result.success(userOrderService.historyOrders(ordersPageQueryDTO));
    }

    @ApiOperation("再来一单")
    @GetMapping("/repetition/{id}")
    public Result<Object> repetition(@PathVariable Long id) {
        return userOrderService.repetition(id);
    }

    @ApiOperation("取消订单")
    @PutMapping("/cancel/{id}")
    public Result<Object> cancel(@PathVariable Long id) {
        userOrderService.cancel(id);
        return null;
    }

    @ApiOperation("催单")
    @GetMapping("/reminder/{id}")
    public Result<Object> reminder(@PathVariable Long id) {
        userOrderService.reminder(id);
        return null;
    }
}
